package start;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;

public class gui extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField tf_first_name;
	private JTextField tf_last_name;
	private JButton btnAnzeigenkonsole;
	private int anzahl = Integer.parseInt(sql.anzahlAuslesen());

	/**
	 * Launch the application.
	 */
	public static void guiStarten() {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					gui frame = new gui();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @throws UnsupportedLookAndFeelException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 * @throws ClassNotFoundException 
	 */
	public gui() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
		setBounds(100, 100, 266, 185);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		tf_first_name = new JTextField();
		tf_first_name.setToolTipText("vorname");
		tf_first_name.setBounds(53, 26, 164, 28);
		contentPane.add(tf_first_name);
		tf_first_name.setColumns(10);
		
		tf_last_name = new JTextField();
		tf_last_name.setToolTipText("nachname");
		tf_last_name.setBounds(53, 56, 164, 28);
		contentPane.add(tf_last_name);
		tf_last_name.setColumns(10);
		
		final JLabel lbl_anzahl = new JLabel(Integer.toString(this.anzahl));
		lbl_anzahl.setBounds(53, 6, 164, 16);
		contentPane.add(lbl_anzahl);
		
		JButton btnHinzufuegen = new JButton("Hinzuf\u00FCgen");
		btnHinzufuegen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String first_name = tf_first_name.getText();
				String last_name = tf_last_name.getText();
				sql.addNameList(first_name, last_name);
				anzahl++;
				lbl_anzahl.setText(Integer.toString(anzahl));
			}
		});
		btnHinzufuegen.setBounds(53, 87, 164, 29);
		contentPane.add(btnHinzufuegen);
		
		btnAnzeigenkonsole = new JButton("Anzeigen (Konsole)");
		btnAnzeigenkonsole.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				sql.printNameList();
			}
		});
		btnAnzeigenkonsole.setBounds(53, 115, 164, 29);
		contentPane.add(btnAnzeigenkonsole);

	}
}
